//
//  ZDPBDismissAnimation.m
//  OCSinaWeiBo
//
//  Created by Apple on 15/11/11.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZDPBDismissAnimation.h"
#import "ZDPhotoBrowserViewController.h"

@implementation ZDPBDismissAnimation


- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
    return 0.5;
}


- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    //取出要dismiss得视图
    UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];
    
    //取出容器视图
    UIView *transitionView = [transitionContext containerView];
    
    //添加到容器视图
    [transitionView addSubview:fromView];
    
    //取出将要dismiss的控制器
    ZDPhotoBrowserViewController *pbVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
    
    //取出过渡视图
    UIImageView *tempImageView = [pbVC dismissTempImageView];
    
    //添加到容器视图
    [transitionView addSubview:tempImageView];
    
    pbVC.photoBrowserCollectionView.hidden = YES;
    
    [UIView animateWithDuration:[self transitionDuration:nil] animations:^{
        
        fromView.alpha = 0;
        
        tempImageView.frame = [pbVC dismissTempViewEndFrame];
        
    } completion:^(BOOL finished) {
        
        pbVC.photoBrowserCollectionView.hidden = NO;
        
        //通知系统 转场动画结束
        [transitionContext completeTransition:YES];
    }];
}


@end
